<include file="Public/header" /> 
<script src="__PUBLIC__/js/uploadify/jquery.uploadify.min.js"></script>

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4><{$defSubTitle}></h4>
		<form class="form-horizontal" id="myform" name="myform">
			<div class="form-group">
				<label for="title" class="col-sm-2 control-label">产品标题</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="title" id="title" value="<{$data['title']}>" placeholder="产品标题">
				</div>
			</div>

			<div class="form-group">
				<label for="title" class="col-sm-2 control-label">网址</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="url" id="url" value="<{$data['url']}>" placeholder="网址">
				</div>
			</div>

			<div class="form-group">
				<label for="cid" class="col-sm-2 control-label">所属栏目</label>
				<div class="col-sm-5">
					<select class="form-control" name="cid">
  						<option value="0">-请选择栏目-</option>
  						<foreach name="cate" item="vo">
  							<option value="<{$vo['id']}>" <if condition="$data['cid'] eq $vo['id']">selected</if>><if condition="$vo['parent_id'] neq 0">&nbsp;&nbsp;&nbsp;&nbsp;</if><{$vo['name']}></option>
  						</foreach>
  					</select>
				</div>
			</div>
			
			<div class="form-group">
				<label for="taxis" class="col-sm-2 control-label">排序</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="taxis" id="taxis" value="<{$data['taxis']|default="100"}>" placeholder="自定义排序，值越大越靠前.">
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">是否显示</label>
				<div class="radio col-sm-5">
					<label>
						<input type="radio" name="status" id="status1" value="1" <if condition="$data['status'] eq 1">checked</if>>
					   	显示
					</label>
					<label>
						<input type="radio" name="status" id="status0" value="-1" <if condition="$data['status'] eq -1">checked</if>>
					   	隐藏
					</label>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">按钮类型</label>
				<div class="radio col-sm-5">
					<label>
						<input type="radio" name="button_type" id="button_type" value="0" <if condition="$data['button_type'] eq 0">checked</if>>
					   	无样式
					</label>
					<label>
						<input type="radio" name="button_type" id="button_type" value="1" <if condition="$data['button_type'] eq 1">checked</if>>
					   	悬浮
					</label>
				</div>
			</div>

			<div class="form-group" id="button_position">
				<label class="col-sm-2 control-label">按钮样式</label>
				<div class="radio col-sm-5">
					<label>
						<input type="radio" name="button_position" id="button_position" value="0" <if condition="$data['button_position'] eq 0">checked</if>>
					   	顶部
					</label>
					<label>
						<input type="radio" name="button_position" id="button_position" value="1" <if condition="$data['button_position'] eq 1">checked</if>>
					   	底部
					</label>
				</div>
			</div>

			<div class="form-group">
				<label for="" class="col-sm-2 control-label">产品图片</label>
				<div class="col-sm-5">
					<div class="upload-file-box" style="width:350px">
						<div class="radio col-sm-5">
							<a class="btn btn-default" id="uploadify">上传产品图片</a> <span style="margin-top:10px;float:left;color:#999">（仅允许上传1MB以内的图片）</span>
						</div>
						<div id="upload-file-view" class="OneImageBox upload-view">
							<div id="showimg">
						
								<if condition="!empty($data['thumb'])">
									<div style="width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float:left;">
										<img src="<{$data['thumb']}>" style="width:100px;height:100px;float:left;margin:0 auto;padding:5px;">
										<div onclick="removeImg();" style="height:30px;width:100%;background:#000;opacity:.6;text-align:center;z-index:3;position:relative;bottom:30px;color:#fff;line-height:30px;float:left;cursor:pointer;">删除</div>
									</div>
									<input type="hidden" class="img_input" name="thumb" value="<{$data['thumb']}>">
								</if>
							</div>
	
						</div>
					</div>
				</div>
			</div>
			
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="hidden" name="id" value="<{$data['id']}>"/>
					<button type="submit" class="btn btn-default col-sm-2">保存</button>
				</div>
			</div>
		</form>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/validate/messages_zh.js"></script>
<script>
function button_position_status(value){
	if(value == '0'){
		$("#button_position").hide();
	}else{
		$("#button_position").show();
	}
}
	
//移除图片
function removeImg(obj){
	$(obj).parent().remove();
}

// 文件上传
$("#uploadify").uploadify({
	'swf'           : '/Public/js/uploadify/uploadify.swf',
	'uploader'      : "<?php echo U('Admin/Gallery/uploadImg');?>",
	'fileTypeExts'	: '*.jpg;*.png;*.gif',
	'width'			: 90,
	'buttonText' : '<a class="btn btn-default" id="uploadify">上传图片</a>',
	'hideButton' : true,
	'multi': false,
	'fileObjName' : 'imgFile',
	'fileSizeLimit' : '1MB',
	'multi'    : false, //开启,多选文件
	'uploadLimit' : 1, //允许上传文件个数
	'onUploadError' : function(back) {
		
	},
	'onUploadStart' : function(file) {

	},
	'onUploadSuccess' : function(file,data,response) {
		var r = jQuery.parseJSON(data);
		if(r.error == 0){
			var htm = '<div style="width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float:left;margin-bottom:10px;">';
			htm += '<img src="/'+r.imgUrl+'" style="width:100px;height:100px;float:left;margin:0 auto;padding:5px;">';
			htm += '<div onclick="removeImg(this);" style="height:30px;width:100%;background:#000;opacity:.6;text-align:center;z-index:3;position:relative;bottom:30px;color:#fff;line-height:30px;float:left;cursor:pointer;">删除</div>';
			htm += '<input type="hidden" class="img_input" name="thumb" value="/'+r.imgUrl+'"/>';
			htm += '</div>';
			$("#showimg").append(htm);
		}
	},

});	

$(function(){
	
	//移除图片
	function removeImg(obj){
		$(obj).parent().remove();
	}
	
	$("input[name='button_type']").change(function(){
		var value = $(this).val();

			button_position_status(value);
	});

	var button_type = $("input[name='button_type']:checked").val();

	button_position_status(button_type);

	$('#taxis').on('click', function(){
	    var that = this;
	    layer.tips('自定义排序，值越大越靠前.', that, {
		    tips: [2, '#3595CC'],
		});
	});

	$('#seo_key').focus(function() {
		var index = layer.tips('用逗号[英文半角]分隔,字数推荐20字以内',"#seo_key",{time:0});
		$(this).blur(function() {
			layer.close(index);
		});
	});

	$('#seo_depict').focus(function() {
		var index = layer.tips('字数推荐150字以内',"#seo_depict",{time:0});
		$(this).blur(function() {
			layer.close(index);
		});
	});
	
	$("#myform").validate({
		rules: {
			title : {
				required : true
            },
            cid : {
            	min:1
            }
		},
		messages: {
			cid : {
				min : "请选择栏目"
			}
		},
		submitHandler : function(form){
			<if condition="C('editor') eq 'ueditor'">
			ue.sync("myform");
			</if>
			var ajaxUrl = "<{$ajaxUrl ? $ajaxUrl : U('Admin/Product/add_product')}>";
			 $.post(ajaxUrl,$("#myform").serialize(),function(r){
    			if (r.error == 1){
    				layer.alert(r.errmsg,{icon: 2});
    			}else{
    				layer.alert(r.errmsg,{icon: 1},function(){
    					window.location.href = "<{:U('Admin/Product/index',array('k'=>11,'sk'=>0))}>";
    				});
    			}
    			return false;
    		});
        	return false
		}
	});
});
</script>

<include file="Public/footer" /> 